﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BUS
{
    public class XuLyHoaDon
    {
        // tim ds khach hang chua tra phong
        public static DataTable TimDSKhachHang()
        {
            // lop DataProvider
            DAO.CDataProvider reader = new DAO.CDataProvider();
            // chuoi SELECT
            String sql = " SELECT DISTINCT kh.MaKH as MaKH,kh.HoTen as HoTen,kh.Tuoi as Tuoi,kh.DiaChi as DiaChi,kh.CMND as CMND FROM KHACHHANG kh,PHIEUTHUE pt WHERE kh.MaKH = pt.MaKH AND pt.TinhTrang = 0 ";

            DataTable dt = new DataTable();
            try
            {
                // Bang data se duoc nhap
                dt = reader.DocDuLieu(sql);
            }
            catch (System.Exception)
            {

            }
            return dt;
        }
        // lay toan bo hoa don

        // lay thong tin 1 hoa don

        // them 1 hoa don
        public static Boolean ThemHoaDon(DTO.CHOADON hd)
        {
            DAO.CDataProvider writer = new DAO.CDataProvider();

            // Cau lenh SQL
            String insertSQL = " INSERT INTO HOADON(MaKH,TenKH,SoNgayThue,ThanhTien,NgayLap) "
                + " VALUES(" + hd.MaKH.ToString() + ","
                + "'" + hd.TenKH.ToString() + "',"
                + " " + hd.SoNgayThue.ToString() + ","
                + " " + hd.ThanhTien.ToString() + ","
                + "'" +hd.NgayLap.ToString() + "') ";

            // Thuc thi cau lenh insert
            if (writer.ThucThiDuLieu(insertSQL))
                return true;
            else
                return false;
        }
        // xoa 1 hoa don
    }
}
